<template>
  <div class="common-layout" style="width: 1320px; padding-top: 20px">
    <el-container>
      <el-header>
        <Searchers
          :isSortShow="false"
          style="margin: 0"
          str3="请输入订单编号"
          str4="今日退款订单"
          str5="500单"
          str6="累计退款订单"
          str7="5000单"
        >
          <div class="menuTop">
            <div class="screen">
              <el-icon><Filter /></el-icon>
              <span>筛选</span>
            </div>
            <span class="spanLei">退款类型：</span>
            <el-select
              v-model="refundInput"
              placeholder="请选择退款类型"
              style="width: 145px"
            >
              <el-option label="直接换货" value="1" />
              <el-option label="退货退款" value="2" />
            </el-select>
            <div class="block">
              <span class="demonstration">申请时间：</span>
              <el-date-picker
                v-model="applyInput"
                type="daterange"
                start-placeholder="开始时间"
                end-placeholder="结算时间"
                :default-value="[new Date(2022, 12, 1), new Date(2023, 1, 1)]"
                style="width: 200px"
              />
            </div>
          </div>
        </Searchers>
      </el-header>
      <el-main>
        <ul>
          <li :class="{ active: 0 === tabGoods }" @click="tabCuts(0)">
            全部订单<span>30</span>
          </li>
          <li :class="{ active: 1 === tabGoods }" @click="tabCuts(1)">
            待处理<span>30</span>
          </li>
          <li :class="{ active: 2 === tabGoods }" @click="tabCuts(2)">
            处理中<span>30</span>
          </li>
          <li :class="{ active: 3 === tabGoods }" @click="tabCuts(3)">
            已处理<span>30</span>
          </li>
        </ul>
        <TotalGoods
          :tableData="wholeOrder.allOrderList"
          v-show="0 === tabGoods"
          v-loading="loading"
        ></TotalGoods>
        <TotalGoods
          :tableData="waitList"
          v-show="1 === tabGoods"
          v-loading="loading"
        ></TotalGoods>
        <TotalGoods
          :tableData="nowList"
          v-show="2 === tabGoods"
          v-loading="loading"
        ></TotalGoods>
        <TotalGoods
          :tableData="overList"
          v-show="3 === tabGoods"
          v-loading="loading"
        ></TotalGoods>
      </el-main>
      <Footer
        :num1="20"
        :num2="wholeOrder.counts"
        :total="wholeOrder.counts"
        :pageSizes="wholeOrder.ls"
        @changePage="changePage"
        @myEvent="myEvent"
        @myEvent2="myEvent2"
        @myEvent3="myEvent3"
      ></Footer>
    </el-container>
  </div>
</template>

<script setup>
import TotalGoods from "./states/TotalGoods.vue";
import Searchers from "../components/Search.vue";
import Footer from "../components/Footer.vue";

import { ref, reactive } from "vue";
import { useOrderData } from "../stores/allOrder.js";
import { getList } from "../api/SaleFinance";

const { wholeOrder } = useOrderData();

// 已处理数组
const overList = ref([]);
// 处理中数组
const nowList = ref([]);
// 待处理数组
const waitList = ref([]);

async function getSaleList(page) {
  await getList(page).then((res) => {
    res.data.items.forEach((item) => {
      if (item.state === "2") {
        item.state = "已处理";
        overList.value.push(item);
      } else if (item.state === "1") {
        item.state = "处理中";
        nowList.value.push(item);
      } else if (item.state === "0") {
        item.state = "待处理";
        waitList.value.push(item);
      }
    });
    // console.log(res);
    wholeOrder.allOrderList = res.data.items;
    wholeOrder.currentPage = res.data.cp;
    wholeOrder.counts = res.data.count;
    wholeOrder.showNum = res.data.ls;
  });
}

const refundInput = ref("");
const applyInput = ref("");

const loading = ref(false);
// 设置初值0
const tabGoods = ref(0);
/**
 * tabCuts
 * 控制点击订单状态的切换效果
 * @param {number} index
 */
function tabCuts(index) {
  tabGoods.value = index;
  loading.value = true;
  setTimeout(() => {
    loading.value = false;
  }, 3000);
}

// 请求第几页的数据
// const test = ref(1);

// 首页
async function myEvent(first) {
  await getSaleList(first);
}
myEvent();

// 下一页
async function myEvent2(down) {
  await getSaleList(down);
}

// 上一页
async function myEvent3(up) {
  await getSaleList(up);
}

// 切换页码
function changePage(index) {
  console.log(index);
}
</script>

<style lang="less" scoped>
.el-header,
.el-main,
.el-footer {
  margin: 0;
  padding: 0;
}
.common-layout {
  .el-header {
    height: 30%;
    border-radius: 5px;
    box-shadow: 0px 0px 20px rgb(0 0 0 / 20%);
    font-size: 12px;
    font-weight: bold;
    padding: 0;
    .el-icon {
      font-size: 20px;
      color: blue;
      margin-left: 15px;
    }
    .menuTop {
      display: flex;
      align-items: center;
      margin-top: 50px;
      .screen {
        display: flex;
        align-items: center;
        span {
          margin-left: 7px;
        }
      }
      .spanLei {
        margin-left: 25px;
        display: block;
        width: 80px;
      }
      .block {
        display: flex;
        align-items: center;
        margin-left: 25px;
      }
    }
    .menuBottom {
      display: flex;
      align-items: center;
      margin-top: 30px;
      .searchImg {
        display: flex;
        align-items: center;
        span {
          margin-left: 10px;
        }
      }
      .searchInput {
        width: 400px;
        display: flex;
        align-items: center;
        margin-left: 25px;
        span {
          display: block;
          width: 80px;
        }
      }
    }
    .btn {
      margin-top: 30px;
    }
  }
  .el-main {
    height: 100%;
    margin-top: 25px;
    box-shadow: 0px 0px 20px rgb(0 0 0 / 20%);
    border-radius: 5px;
    li {
      display: inline-block;
      width: 100px;
      height: 50px;
      color: #000;
      text-decoration: none;
      text-align: center;
      line-height: 50px;
      margin-left: 15px;
      font-weight: bold;
      cursor: pointer;
      position: relative;
      span {
        margin-left: 10px;
        color: blue;
      }
    }
    .active {
      color: blue;
      &::after {
        content: "";
        display: block;
        width: 100px;
        height: 2px;
        background: blue;
        border-radius: 2px;
        position: absolute;
        left: 0;
        bottom: 0;
      }
    }
  }
}
</style>
